﻿<!DOCTYPE html>
<html>
	<head>
		<title>操作列表</title>
    $css()
	</head>
	<body>	

<div class="_tabarea">
<!--
    <div class="tab_mini">
        <a href="?module=user&amp;action=systemuserlist">系统用户</a>
        <a href="?module=user&amp;action=setpermissions">用户组权限设置</a>
        <a href="javascript:;l" class="current">权限管理</a>
    </div>
    -->
        <div class="area">

<table class="ui-table" cellspacing="0" cellpadding="0" id="operations">
      <tr>
        <th width="40">编号</th>
        <th width="210" style="text-align:left" class="tleft">操作名称</th>
        <th style="text-align:left" class="tleft">执行路径</th>
        <th width="40">可用</th>
        <th width="70">保存</th>
      </tr>
      <tr>
        <td><strong>新增</strong></td>
        <td><input type="text" class="tb_normal"/></td>
        <td><input type="text" class="tb_normal"/></td>
        <td colspan="2" align="right"><a href="javascript:;" id="btncreate" class="btn">提交</a></td>
      </tr>

      ${operationRowsHtml}

</table>
<div class="pager">${pagerHtml}</div>
</div>

</div>

$js()
<script type="text/javascript">

    var tb = cms.$('operations');
    cms.table.dynamic(tb);

  cms.$('btncreate').onclick = function () {
    var tds = this.parentNode.parentNode.getElementsByTagName('input');
    var name = tds[0].value,
      path = tds[1].value;

    if (name == '')  parent.M.alert('请输入操作名称！');
    else if (path == '') parent.M.alert('请输入操作路径！');
    else {
      cms.xhr.post('?', 'module=user&action=createoperation&name=' + escape(name) + '&path=' + escape(path),
        function (x) {
          location.reload();
        }, function (x) { alert(x); });
    }
  };

  var btns = cms.$('operations').getElementsByTagName('button');
  for (var i = 0; i < btns.length; i++) {
    btns[i].onclick = (function (elem) {
      return function () {
        var tds = elem.parentNode.parentNode.getElementsByTagName('td');
        var id = tds[0].innerHTML,
            name = escape(tds[1].childNodes[0].value),
            path = escape(tds[2].childNodes[0].value),
            available = tds[3].childNodes[0].checked;

        cms.xhr.post('?', 'module=user&action=updateoperation&id=' + id + '&name=' + name + '&path=' + path + '&available=' + available,
        function (x) {  parent.M.alert('修改成功！'); }, function (x) { alert(x); });

      };
    })(btns[i]);
  }

</script>

	
	</body>
</html>